var tmpPlayer = require("Player");

cc.Class({
    extends: cc.Component,

    properties: {
        dieAudio: {
            default: null,
            url: cc.AudioClip
        },
    },

    setInputControl: function() {
        var self = this;

        var listener = {
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            onTouchBegan: function(touched, event) {
                var goAction = cc.moveBy(0.2, cc.p(0, 140));
                self.node.runAction(goAction);
                return true;
            }
        }

        cc.eventManager.addListener(listener, self.node);
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    nodeBox: function() {
        return this.node.getBoundingBoxToWorld();
    },

    start() {
        cc.audioEngine.setEffectsVolume(0.2);
        this.setInputControl();
    },

    update: function() {
        var player = cc.find("Canvas/normal").getComponent(tmpPlayer);
        if (cc.rectIntersectsRect(player.node.getBoundingBoxToWorld(), this.nodeBox())) {
            cc.audioEngine.playEffect(this.dieAudio, false);
            cc.director.loadScene("OverScene");
        }
    }
});